#ifndef						_TFIDF_H_
#define						_TFIDF_H_

#include <string>
#include <vector>
#include <unordered_map>
#include "SparseMatrix.h"

class CDictionary;

class CTFIDF
{
public:
	CTFIDF();
	~CTFIDF();

	bool					Create(std::vector<std::string>& documents);
	bool					Destroy();

	bool					FlagCreate() {	return m_bFlagCreate; }

	std::vector<std::pair<int, float> >	SimilarDocs(std::string query);
	int						SimilarDoc(std::string query);

private:
	bool					m_bFlagCreate;
	CDictionary*			m_ptrDictionary;
	SparseMatrix<float>		m_tfidf;
	SparseMatrix<int>		m_termFreq;
	std::unordered_map<int, float> m_dicLength;
	int						m_nDocSize;

protected:
	inline float			t_InnerProduct(std::unordered_map<int, int> a, int nRow);
	inline float			t_LengthVec(std::unordered_map<int, int> a);
	inline float			t_LengthVec(int nRow);
	void					t_InitLengthVec();
	int						t_DocFreq(int nIndex);
};

#endif						//_TFIDF_H_
